/*

by Luigi Auriemma

*/

NOTIFYICONDATA  tray;
#define UWM_SYSTRAY WM_USER + 1



LRESULT CALLBACK wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
    switch (message) {
        case WM_CREATE:
            return(TRUE);
        case WM_DESTROY:
            tray.cbSize = sizeof(NOTIFYICONDATA);
            tray.hWnd   = hwnd;
            Shell_NotifyIcon(NIM_DELETE, &tray);
            PostQuitMessage(0);
            return(TRUE);
        case UWM_SYSTRAY:
            return(TRUE);
    }
    return(DefWindowProc(hwnd, message, wParam, lParam));
}



void gsweb_tray(void) {
    HWND            hwnd;
    HINSTANCE       hInstance = NULL;
    WNDCLASSEX      wc;
    char            *classname =
                    "Gslist.NOTIFYICONDATA.hWnd";

    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = 0;
    wc.lpfnWndProc   = wndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = NULL;
    wc.hCursor       = NULL;
    wc.hbrBackground = NULL;
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = classname;
    wc.hIconSm       = NULL;

    RegisterClassEx(&wc);

    hwnd             = CreateWindowEx(
                        0,
                        classname,
                        classname,
                        WS_POPUP,
                        CW_USEDEFAULT,
                        CW_USEDEFAULT,
                        CW_USEDEFAULT,
                        CW_USEDEFAULT,
                        NULL,
                        NULL,
                        hInstance,
                        NULL);

    tray.cbSize           = sizeof(tray);
    tray.hWnd             = hwnd;
    tray.uID              = 1;
    tray.uFlags           = NIF_MESSAGE | NIF_ICON | NIF_TIP;
    tray.uCallbackMessage = UWM_SYSTRAY;
    tray.hIcon            = LoadIcon(NULL, IDI_APPLICATION);
    strcpy(tray.szTip,      "Gslist");

    Shell_NotifyIcon(NIM_ADD, &tray);
}


